package com.baijia.authentication.principal.resolver;

import com.baijia.authentication.AccountType;
import com.baijia.authentication.principal.Credentials;
import com.baijia.authentication.principal.credentials.JigouCascadeAccountCredentials;

import com.google.common.collect.Maps;

import org.springframework.stereotype.Component;

import java.util.Map;


/**
 * @title JigouPrincipalResolver
 * @desc 读取机构详细信息并且填充 
 * @author caoliang
 * @date 2015年12月5日
 * @version 1.0
 */
@Component
public class JigouCascadeAccountPrincipalResolver extends AccountTypeCredentialsToPrincipalResolver {
    
    @Override
    public int getAccountType() {
        return AccountType.ORG_SUB_ACCT.getCode();
    }
    
    @Override
    protected String extractPrincipalId(final Credentials credentials) {
        final JigouCascadeAccountCredentials usernamePasswordCredentials = (JigouCascadeAccountCredentials) credentials;
        return usernamePasswordCredentials.getUsername();
    }

    @Override
    public boolean supports(final Credentials credentials) {
        if (!(credentials instanceof JigouCascadeAccountCredentials)) {
            return false;
        }

        final JigouCascadeAccountCredentials accountTypedCredentials = (JigouCascadeAccountCredentials) credentials;
        if (getAccountType() != accountTypedCredentials.getAccountType()) {
            return false;
        }

        return true;
    }

    @Override
    protected Map<String, Object> generateAttributes(Credentials credentials) {

        return Maps.newHashMap();
    }
}

    